#include "MouseLabel.h"
#include "OneKeyboardStruct.h"

MouseLabel::MouseLabel(QWidget *parent)
	: QLabel(parent)
{
	refreshColor();
}

MouseLabel::~MouseLabel()
{
}

void MouseLabel::refreshColor(const DataHandler::Data& data)
{
	// 0 rgb(221, 221, 221)  max rgb(255, 0, 0)

	int maxCount = data.getMouseMax();

	double per1 = maxCount == 0 ? 0 : ((255 - 221) / std::pow(maxCount * 1.0, COLOR_POW_NUM));
	double per2 = maxCount == 0 ? 0 : (-221 / std::pow(maxCount * 1.0, COLOR_POW_NUM));

	double powLeft = std::pow(data.mLeft * 1.0, COLOR_POW_NUM);
	double powRight = std::pow(data.mRight * 1.0, COLOR_POW_NUM);
	double powMid = std::pow(data.mMid * 1.0, COLOR_POW_NUM);

	QPixmap img = getMouseSVGPixmap(QString("rgb(%1, %2, %2)").arg(221 + per1 * powLeft).arg(221 + per2 * powLeft)
		, QString("rgb(%1, %2, %2)").arg(221 + per1 * powRight).arg(221 + per2 * powRight)
		, QString("rgb(%1, %2, %2)").arg(221 + per1 * powMid).arg(221 + per2 * powMid));
	setPixmap(img);
}
